package com.homework.HomeAcount.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.homework.HomeAcount.dao.AcountDao;
import com.homework.HomeAcount.entity.Acount;
import com.homework.HomeAcount.service.AcountService;

@Service("acountService")
public class AcountServiceImpl implements AcountService {

	@Autowired
	private AcountDao acountDao;
	
	@Override
	public List<Map<String, Object>> loadAcountList(int pageSize,int pageNumber,Map<String, Object> paramMap) {
//		Map<String, Object> map = new HashMap<String, Object>();
		paramMap.put("pageSize", pageSize);
		paramMap.put("pageNumber", pageNumber);
		return acountDao.loadAcountList(paramMap);
	}

	@Override
	public int getListSize(Map<String, Object> paramMap) {
		return acountDao.getListSize(paramMap);
	}

	@Override
	public List<Map<String, Object>> getAcountTypeList(String balance) {
		balance = StringUtils.trimToNull(balance);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("balance", balance);
		return acountDao.getAcountTypeList(map);
	}

	@Override
	public List<Map<String, Object>> getAcountForwhoList() {
		return acountDao.getAcountForwhoList();
	}

	@Override
	public Map<String, Object> loadAcountById(String id) {
		Map<String, Object> reMap = new HashMap<String, Object>();
		Acount acount =  acountDao.loadAcountById(id);
		reMap.put("acount", acount);
		if(null != acount && !StringUtils.isEmpty(acount.getBalance())) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("balance", acount.getBalance());
			List<Map<String, Object>> list = acountDao.getAcountTypeList(map);
			reMap.put("typeList", list);
		}
		return reMap;
	}

	@Override
	public void updateAcountById(Acount acount) throws Exception {
		acountDao.updateAcountById(acount);
	}

	@Override
	public void addAcount(Acount acount) throws Exception {
		acountDao.addAcount(acount);
	}

	@Override
	public void deleteAcountById(String id) throws Exception {
		acountDao.deleteAcountById(id);
	}

}
